package com.dw.widget.slideshow2.utils;

import com.dw.widget.slideshow2.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.os.Environment;
import android.widget.Toast;

public class CommonUtils {

	public void PrintLog(String log)
	{
		
	}
	
	public static boolean isInstalled(Context context, String packageName)
	{
		 if (packageName == null || "".equals(packageName))
         {
             return false;
         }
         try
         {
             context.getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES);
             return true;
         }
         catch (NameNotFoundException e)
         {
              return false;
         }
	}
	
	/*
	 * 短时Toast
	 */
	public static void showShortToast(Context context, String msg)
	{
		Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
	}
	
	/*
	 * 长时Toast
	 */
	public static void showLongToast(Context context, String msg)
	{
		Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
	}
	
	public static void showDialog(Context context, String title, String msg, OnClickListener yesListener)
	{
		new AlertDialog.Builder(context)
			.setTitle(title)
			.setMessage(msg)
			.setPositiveButton(context.getString(R.string.ok),  yesListener)
			.setNegativeButton(context.getString(R.string.cancel), null)
			.show();
	}
	
	public static String getDCIMPath()
	{
		String dcimPath = Environment.getExternalStorageDirectory() + "/DCIM";
		
		int sysVersion = Integer.parseInt(VERSION.SDK);
		if(sysVersion >= 8)     // >= Android 2.2
		{
			dcimPath = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM;
		}
		
		return dcimPath;
	}
	
	public static String getDCIMName()
	{
		String dcim = "DCIM";
		
		int sysVersion = Integer.parseInt(VERSION.SDK);
		if(sysVersion >= 8)     // >= Android 2.2
		{
			dcim = Environment.DIRECTORY_DCIM;
		}
		
		return dcim;
	}
}
